﻿namespace System.ServiceModel.DomainServices.Client
{
    using System;
    using System.Collections.Generic;
    using System.Text;

    internal class EntityKey<T> : EntityKey, IEquatable<EntityKey<T>>
    {
        private T _v;

        public EntityKey(T v)
        {
            EntityKey.VerifyKeyValueNotNull(v);
            this._v = v;
        }

        public override bool Equals(object obj)
        {
            return this.Equals((EntityKey<T>) obj);
        }

        public bool Equals(EntityKey<T> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }
            return EqualityComparer<T>.Default.Equals(this._v, other._v);
        }

        internal override void FormatKey(StringBuilder sb)
        {
            EntityKey.FormatKeyValue<T>(sb, this._v);
        }

        public override int GetHashCode()
        {
            return this._v.GetHashCode();
        }
    }
}

